package javaStudy;

public class StringBuilderdemo {
    //String内容不可变，StringBuilder内容可变
    //构造方法
    public static void main(String[] args) {
        //构造方法
        StringBuilder sb=new StringBuilder("hello");
        //append方法返回对象本身
        sb.append("world");
        sb.append("java");
        sb.append(1000);
        System.out.println(sb);
        //将sb反转，并返回sb
        sb.reverse();
        System.out.println(sb);
        System.out.println(sb.length());

        //String 和 StringBuilder相互转换
        String s1="sdfdsaf";
        StringBuilder sb1=new StringBuilder(s1);
        System.out.println(sb1);

        StringBuilder sb2=new StringBuilder("sdfesfasd");
        String s2=sb2.toString();
        System.out.println(s2);
    }
}
